<template>
  <header class="head-nav">
    <el-row>
      <el-col :span="6" class="login-container">
        <img src="../assets/logo.webp" class="logo" alt="">
        <span class="title">米修在线后台管理系统</span>
      </el-col>
      <el-col :span="2" class="user">
        <div class="welcome">
          <p class="name comename">欢迎</p>
          <p class="name avatarname">{{ user.name }}</p>
        </div>
        <span class="username">
          <el-dropdown trigger="click" @command="handleCommand">
            <span class="el-dropdown-link">
              <i class="el-icon-caret-bottom el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="info">个人信息</el-dropdown-item>
              <el-dropdown-item command="logout">退出</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </span>
      </el-col>
    </el-row>
  </header>
</template>

<script>
export default {
  name: 'head-nav',
  computed: {
    user() {
      return this.$store.getters.user
    }
  },
  methods: {
    handleCommand(cmdItem) {
      switch (cmdItem) {
        case 'info':
          this.showInfoList();
          break
        case 'logout':
          this.logout()
          break
      }
    },
    showInfoList() {
      this.$router.push('/infoshow')
    },
    logout() {
      localStorage.removeItem('eleToken')
      this.$store.dispatch('clearCurrentState')
      this.$router.push('/login')
    }
  }
}
</script>

<style scoped>
.title {
  display: block;
  margin-left: 60px;
  margin-top: -40px;
  font-size: 20px;
  /* height: 20px;
  line-height: 20px; */
}

.user {
  float: right;
  position: relative;
  /* display: block; */
}

.logo {
  height: 20%;
  width: 10%;
  margin-top: 10px;
}

.head-nav {
  width: 100%;
  height: 60px;
  line-height: 30px;
  min-width: 600px;
  padding: 5px;
  background: #324057;
  color: #fff;
  border-bottom: 1px solid #1f2d3d;
}

.username {
  position: absolute;
  top: 40px;
  cursor: pointer;
  margin-right: 5px;

}

.avatarname {
  color: #409eff;
  font-weight: 5px;
}

.comename {
  font-style: 12px;
}

.el-dropdown {
  color: #fff;
}
</style>

